#!/usr/bin/perl
use strict;
my @all_mus_gene_ids;
my @all_rat_gene_ids;
sub print_summary
{
	my $cnt_mus = @all_mus_gene_ids;
	my $cnt_rat = @all_rat_gene_ids;
	print STDERR "\t", $cnt_mus, "\tmouse genes\n";
	print STDERR "\t", $cnt_rat, "\trat genes\n";
	print STDERR "\t", $cnt_mus  +$cnt_rat, "\tgenes in total\n";
	my %all_mus_gene_ids;
	@all_mus_gene_ids{@all_mus_gene_ids} = ();
	my %all_rat_gene_ids;
	@all_rat_gene_ids{@all_rat_gene_ids} = ();
	if (keys %all_mus_gene_ids < $cnt_mus)
	{
		print STDERR "\t", scalar keys %all_mus_gene_ids, "\tunique mus genes\n";
		print STDERR "\t", $cnt_mus - scalar keys %all_mus_gene_ids, "\tduplicate mus genes\n";
	}
	if (keys %all_rat_gene_ids < $cnt_rat)
	{
		print STDERR "\t", scalar keys %all_rat_gene_ids, "\tunique rat genes\n";
		print STDERR "\t", $cnt_rat - scalar keys %all_rat_gene_ids, "\tduplicate rat genes\n";
	}
	my $unique_total = scalar keys (%all_mus_gene_ids) + scalar keys (%all_rat_gene_ids);
	print STDERR "\t", $unique_total, "\tunique genes in total\n\n" if $unique_total != $cnt_mus + $cnt_rat;
	print join ("\n", keys %all_rat_gene_ids, keys %all_mus_gene_ids);
	@all_mus_gene_ids = ();
	@all_rat_gene_ids = ();
}

my @files = @ARGV;
while (<>)
{
	my @gene_ids = /(ENSMUS[A-Z]*\d+)/g;
	push(@all_mus_gene_ids, @gene_ids);
	@gene_ids = /(ENSRNO[A-Z]*\d+)/g;
	push(@all_rat_gene_ids, @gene_ids);
	if (eof)
	{
		my $curr_file = shift @files;
		if ($curr_file)
		{
			print STDERR "Genes in $curr_file:\n";
		}
		print_summary;
	}
}
